package com.heima.behavior.feign;


import com.heima.behavior.service.UserBehaviorService;
import com.heima.model.behavior.dtos.BhLikesBehaviorDto;
import com.heima.model.behavior.dtos.ReadCountDto;
import com.heima.model.behavior.dtos.UnLikesBehaviorDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author yht
 * @date 2022/1/15 10:45
 */
@RestController
@Slf4j
@Transactional
public class BehaviorClient {

    @Autowired
    private UserBehaviorService userBehaviorService;

    @PostMapping("/api/v1/like_behavior")
    public ResponseResult liking(@RequestBody BhLikesBehaviorDto dto) {
        if (dto.getOperation() == 0) {
            return userBehaviorService.like(dto);
        }
        if (dto.getOperation() == 1) {
            return userBehaviorService.unLike(dto);
        }
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @PostMapping("/api/v1/findIsLike")
    public ResponseResult findLike(@RequestBody Map map) {
        return userBehaviorService.findIsLike(map);
    }
    /**
     * 不喜欢
     * @return
     */
    @RequestMapping("/api/v1/un_likes_behavior")
    public ResponseResult unLikes(@RequestBody UnLikesBehaviorDto dto){
        return userBehaviorService.unLikes(dto);
    }

    /**
     * 查询是否不喜欢
     * @param map
     * @return 里面是true或者false
     */
    @RequestMapping("/api/v1/findIsUnLike")
    public ResponseResult findIsUnLike(@RequestBody Map map){
       return userBehaviorService.findIsUnLike(map);
    }

    /**
     * 用户阅读
     * @return
     */
    @RequestMapping("/api/v1/readcount")
    public ResponseResult readCount(@RequestBody ReadCountDto dto){
        return userBehaviorService.readCount(dto);
    }
}
